<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="Expires" CONTENT="0">
    <link rel="shortcut icon" href="/rucdbcourse/views/images/ruc_logo_icon.jpg">
    <title>数据库系统概论实验评分系统</title>
    <link href="/rucdbcourse/views/css/register/basic.css" rel="stylesheet">
    <link href="/rucdbcourse/views/css/register/style.css" rel="stylesheet">
    <link href="/rucdbcourse/views/css/bootstrap.min.css" rel="stylesheet">
    <style>
    label {
        font-weight: normal;
    }
    </style>
    <script type="text/javascript" src="/rucdbcourse/views/js/jquery.js"></script>
    <script type="text/javascript" src="/rucdbcourse/views/assets/layer/layer.js"></script>
    <script type="text/javascript" src="/rucdbcourse/views/lib/angular.min.js"></script>
    <script type="text/javascript" src="/rucdbcourse/views/js/vCode.js"></script>
</head>

<body class="login-body" ng-app="myApp" ng-controller="siteCtrl">
    <div class="header">
        <span class='header-pic'><img src="/rucdbcourse/views/images/ruc_logo.png" class="" onclick="window.location.href='/rucdbcourse'"> </span>
        <em>后台管理</em>
    </div>
    <div class="promptBox">
        <div class="prompt establish">
            <label class="establishBox">
                <p>
                    <span>姓名</span>
                    <input type="text" placeholder="请输入姓名" id="TNAME" name="TNAME" ng-model="tname">
                </p>
            </label>
            <label class="establishBox">
                <p>
                    <span>密码</span>
                    <input type="password" placeholder="请输入密码" id="PASSWD" name="PASSWD" maxlength="14" ng-model="passwd">
                </p>
            </label>
            <label class="establishBox">
                <p>
                    <span>邮箱</span>
                    <input type="text" placeholder="请填写邮箱" id="email" name="email" ng-model="email">
                </p>
            </label>
            <label class="establishBox">
                <p>
                    <span><b>*</b>学校</span>
                    <select id="school" style="width:160px" ng-init="selectedUniversity = universities[0]" ng-model="selectedUniversity" ng-options="x for x in universities">
                    <option value="" disabled selected>请选择学校</option>
                    </select>
                    <em style="display: none;">请选择学校</em>
                    
                    <span style="width:50px"><b>*</b>专业</span>
                    <select id="major" style="" ng-init="selectedMajor = majors[0]" ng-model="selectedMajor" ng-options="x for x in majors">
                    <option value="" disabled selected>请选择专业</option>
                    </select>
                    <em style="display: none;">请选择专业</em>
                </p>
            </label>
           
            
            <label class="establishBox">
                <p>
                    
                    <em style="display: none;">请选择课程序号</em>
                    <span id="sequence" style="width:50px"><b>*</b>序号</span>
                    <select style="" ng-init="selecteSequence = classes[0]" ng-model="selectedSequence" ng-options="x for x in classes">
                    <option value="" disabled selected>请选择课程序号</option>
                    </select>
                    <em style="display: none;">请选择课程序号</em>
                </p>
            </label>
            
            <label style="margin-top:20px">
                <div class="login_bnt" style="margin-left:80px">
                    <input type="hidden" name="op_type">
                    <button class="btn btn-lg btn-login btn-block" id="login-btn" ng-click="submited()" type="button">注&nbsp;&nbsp;&nbsp;&nbsp;册</button>
                </div>
            </label>
           
        </div>
        <div class="footer">
            <div class="container">
                Copyright &copy;2005-2017 ruc.edu.cn v1.0 All Rights Reserved. 京ICP备05066828号-1
                <br>
            </div>
        </div>
        <script>
        var app = angular.module('myApp', []);
        app.controller('siteCtrl', function($scope, $http) {
	        //验证码
	        var container1 = document.getElementById("vCode1");
	        var code1 = new vCode(container1);
            //定义学校数组
            $http({
                method: 'GET',
                url: '../user/getUniversities'
            }).then(function(response) {
                // debugger
                // console.log(response)
                $scope.universitiesObj = response.data
                $scope.universities = []
                for (var i = 0; i < $scope.universitiesObj.length; i++) {
                    $scope.universities.push($scope.universitiesObj[i].UNAME)
                }
            }, function(error) {
                console.log(error)
            });

            //定义专业数组
            $http({
                method: 'GET',
                url: '../user/getMajors'
            }).then(function(response) {
                // debugger
                // console.log(response)
                $scope.majorsObj = response.data
                $scope.majors = []
                for (var i = 0; i < $scope.majorsObj.length; i++) {
                    $scope.majors.push($scope.majorsObj[i].MNAME)
                }
            }, function(error) {
                console.log(error)
            });

            //定义年级数组
            $scope.grades = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
            //定义班级数组
            $scope.classes = [1, 2, 3, 4, 5, 6, 7, 8, 9]
            //定义课程数组
            $scope.courses=['数据库系统概论']
			


            $scope.submited = function() {
                // console.log("submit" + $scope.selectedUniversity + $scope.selectedMajor + $scope.selectedGrade + $scope.selecteClass+$scope.selectedSequence)
                var universityNo = 0;
                var majorNo = 0;
                //查询出所选择的学校的代码
                for (var i = 0; i < $scope.universitiesObj.length; i++) {
                    // debugger
                    if ($scope.universitiesObj[i].UNAME == $scope.selectedUniversity) {
                        universityNo = $scope.universitiesObj[i].UNO
                    }
                }
                //查询出所选择专业的代码
                for (var j = 0; j < $scope.majorsObj.length; j++) {
                    // debugger
                    if ($scope.majorsObj[j].MNAME == $scope.selectedMajor) {
                        // console.log($scope.majorsObj[j].MNAME)
                        majorNo = $scope.majorsObj[j].MNO
                    }
                }
                // console.log("uno" + universityNo + "mno" + majorNo + "|" + $scope.selectedGrade + $scope.selecteClass)
				
                if ($("#USER_NAME").val().trim() == "") {
                     $("#USER_NAME").focus();
                     $("#USER_NAME").next().show();
                     return;
                } else {
                     $("#USER_NAME").next().hide();
                }
                
                if ($("#PASSWORD").val().trim() == "") {
                     $("#PASSWORD").focus();
                     $("#PASSWORD").next().show();
                     return;
                } else {
                     $("#PASSWORD").next().hide();
                }
                
                if ($("#repassword").val().trim() == "") {
                    $("#repassword").focus();
                    $("#repassword").next().show();
                    return;
               	} else {
                    $("#repassword").next().hide();
               	}
                if ($("#repassword").val().trim() != $("#PASSWORD").val().trim()) {
                	$("#repassword").focus();
                    layer.msg("两次密码输入不一致 ")
                    return false;
                }
                
                if ($("#email").val().trim() == "") {
                    $("#email").focus();
                    $("#email").next().show();
                    return;
               	} else if(!$("#email").val().trim().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)){
               	 	$("#email").focus();
                    $("#email").next().hide();
                    layer.msg("请输入正确邮箱地址 ")
               	}else {
               		$("#email").next().hide();
               	}
                
                if ($("#USER_REALNAME").val().trim() == "") {
                    $("#USER_REALNAME").focus();
                    $("#USER_REALNAME").next().show();
                    return;
               	} else {
                    $("#USER_REALNAME").next().hide();
               	}
                
                if ($("#school").find("option:selected").text() == "请选择学校") {
                     layer.msg("请选择学校");
                     return;
                }
                
                if ($("#major").find("option:selected").text() == "请选择专业") {
                    layer.msg("请选择专业");
                    return;
               	}
                
                if ($("#grade").find("option:selected").text() == "请选择年级") {
                    layer.msg("请选择年级");
                    return;
               	}
                if ($("#class").find("option:selected").text() == "请选择班级") {
                    layer.msg("请选择班级");
                    return;
               	} 
               	
                if ($("#veryCode").val().trim() == "") {
                    $("#veryCode").focus();
                    layer.msg("请输入验证码");
                    return;
               	} else if(!code1.verify($("#veryCode").val().trim())){
               		$("#veryCode").focus();
            	   	$("#veryCode").next().hide();
                    layer.msg("验证码错误");
                    return;
               	}else{
               	 $("#veryCode").next().hide();
               	}
                //发送注册请求
                $http.post('../user/register',
                        $.param({
                            name: $scope.name,
                            passwd: $scope.passwd,
                            email: $scope.email,
                            realname: $scope.realname,
                            uno: universityNo,
                            mno: majorNo,
                            grade: $scope.selectedGrade,
                            classes: $scope.selecteClass,
                            sequence: $scope.selectedSequence
                        }), {
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                            }
                        })
                    .then(function(response) {
                        // debugger
                        // console.log(response.data)
                        if (response.data.value=="success") {
                            layer.msg("注册成功");
                            window.location="/rucdbcourse/views/info.html?type=2";
                        }else if (response.data.value=="existed") {
                            layer.msg("注册失败，用户已存在");
                        } 
                        else {
                            // console.log(response.data.msg);
                            layer.msg("注册失败，请重试");
                        }
                    });
            };

        });
        </script>
</body>

</html>
